package basics.day16.CalendarDemo;

import java.util.Calendar;
import java.util.Scanner;

public class Test {
    public static void main(String[] args) {
        // fun_1();
        // fun_2();
        // fun_3();
        fun_4();
    }

    /*
     * 计算出自己出生了多少天
     * */
    public static void fun_4() {
        Scanner s = new Scanner(System.in);
        System.out.println("测试您出生了多少天");
        System.out.print("请输入您出生年份：");
        int year = s.nextInt();
        System.out.println("");
        System.out.print("请输入您的出生月：");
        int month = s.nextInt();
        System.out.println("");
        System.out.print("请输入您的出生日：");
        int day = s.nextInt();


        Calendar nowDate = Calendar.getInstance();
        Calendar bothDate = Calendar.getInstance();
        bothDate.set(year, month - 1, day);
        System.out.println("您已经出生了" + (nowDate.getTime().getTime() - bothDate.getTime().getTime()) / 1000 / 60 / 60 / 24 + "天");
    }

    /*
     *	add(int field, int amount)
     *  根据日历的规则，为给定的日历字段添加或减去指定的时间量。
     * */
    public static void fun_3() {
        Calendar c = Calendar.getInstance();
        // 1000代表向后计算1000天之后的时间
        // 1000代表向前计算1000天之后的时间
        c.add(Calendar.DAY_OF_MONTH, -1000);
        System.out.println(c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");
    }

    /*
     * set设置日期
     * */
    public static void fun_2() {
        Calendar c = Calendar.getInstance();
        /*
        // 设置年
        c.set(CalendarDemo.YEAR, 1991);
        System.out.println(c.get(CalendarDemo.YEAR) + "年" + (c.get(CalendarDemo.MONTH) + 1) + "月" + c.get(CalendarDemo.DAY_OF_MONTH) + "日");
         */

        // 设置年月日
        c.set(1991, 1, 15);
        System.out.println(c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DAY_OF_MONTH) + "日");

    }

    /*
     * get获取日期
     * */
    public static void fun_1() {
        Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH) + 1;
        int day = c.get(Calendar.DAY_OF_MONTH);
        System.out.println(year + "年" + month + "月" + day + "日");
    }
}
